package com.ews.onlineexchange.model.approved;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

import com.ews.onlineexchange.model.Attachment;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.Image;

@Entity
public class Evidence extends DataEntity {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	private EvidenceDefination  defination;
	private List<Attachment>	attachments			= new ArrayList<>();
	private List<Image>			images				= new ArrayList<>();

	@ManyToOne
	@NotNull
	public EvidenceDefination getDefination() {
		return defination;
	}

	public void setDefination(EvidenceDefination defination) {
		this.defination = defination;
	}

	@OneToMany(cascade = CascadeType.ALL)
	public List<Attachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<Attachment> attachments) {
		this.attachments = attachments;
	}

	@OneToMany(cascade = CascadeType.ALL)
	public List<Image> getImages() {
		return images;
	}

	public void setImages(List<Image> images) {
		this.images = images;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((attachments == null) ? 0 : attachments.hashCode());
		result = prime * result + ((defination == null) ? 0 : defination.hashCode());
		result = prime * result + ((images == null) ? 0 : images.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Evidence other = (Evidence) obj;
		if (attachments == null) {
			if (other.attachments != null)
				return false;
		} else if (!attachments.equals(other.attachments))
			return false;
		if (defination == null) {
			if (other.defination != null)
				return false;
		} else if (!defination.equals(other.defination))
			return false;
		if (images == null) {
			if (other.images != null)
				return false;
		} else if (!images.equals(other.images))
			return false;
		return true;
	}

}
